package com.seari.service.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.seari.bean.LineInfo;
import com.seari.commonutils.redis.JedisUtilProxy;
import com.seari.commonutils.redis.ex.JedisNotInitializeException;
import com.seari.mapper.LineMapper;
import com.seari.service.LineService;

import redis.clients.jedis.Jedis;

@Service("lineService")
public class LineServiceImpl implements LineService{
	
	@Autowired
	private LineMapper lineMapper;
	
	@Override
	@DS("slave_2")
	public List<LineInfo> getLineListInfoFromJuqun(){
		
		return lineMapper.getLineListInfo();
	}
	
	@Override
	public List<LineInfo> getLineListInfo(){
		
		Jedis jedis = null;
		try {
			jedis = JedisUtilProxy.getJedis();
		} catch (JedisNotInitializeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		String lineObjectJsonString = jedis.get("lineInfoList");
		jedis.close();
		List<LineInfo> list=JSONArray.parseArray(lineObjectJsonString,LineInfo.class);
		LineInfo lineFirstInfo = list.get(0);
		for(int i=0;i<list.size();i++) {
			if(list.get(i).getLineId().equals("0")) {
				list.remove(i);
			}
		}
		list.add(lineFirstInfo);
		return list;
	}
	

}
